#import "ALElementTemplate.h"
#import "ALElement.h"
#import "ALEntryTemplate.h"

@implementation ALElementTemplate


-(ALElement *)stamp {
	ALElement *stampedElement = [ALElement insertInManagedObjectContext:[self managedObjectContext]];
	[stampedElement setLineNumber:[self lineNumber]];
	[stampedElement setElementType:[self elementType]];
	[stampedElement setTemplate:self];
	return stampedElement;
}

-(void)setLineNumber:(NSNumber *)aShortNumber {
    [self willChangeValueForKey:@"lineNumber"];
    [self setPrimitiveLineNumber:aShortNumber];
    [self didChangeValueForKey:@"lineNumber"];
    
    ALEntryTemplate *entry = [self entryTemplate];
    short lineValue = [aShortNumber shortValue];
    if ([entry primaryIsDefaultValue] && lineValue == 0)
        [entry setPrimaryElementTemplate:self];
}

@end
